package com.cybersapien.comng.engine.context;

class ContextManager {

	static ThreadLocal<Context> tlContext = new ThreadLocal<Context>();

	/* ====== SINGLETON MANAGEMENT ===== */

	static private ContextManager instance = null;

	static public ContextManager getInstance() {
		if (instance == null) {
			initInstance();
		}
		return instance;
	}

	static private synchronized void initInstance() {
		if (instance == null) {
			instance = new ContextManager();
		}
	}

	/* ===== */
	private ContextManager() {

	}

	public IContext getContext() {

		IContext context = tlContext.get();
		if (context == null) {
			context = new Context();
			tlContext.set((Context) context);
		}

		return context;
	}

	public void releaseContext() {
		tlContext.set(null);
	}
}
